# 1.导包
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from faker import Faker

fk = Faker(locale="zh_CN")

# 2.创建浏览器驱动对象
# Firefox浏览器:
# driver = webdriver.Firefox()
# Chrome浏览器:
path = r"D:\Programs\Python\Python313\chromedriver.exe"
ser = Service(executable_path = path)
driver = webdriver.Chrome(service = ser)
# 使用Edge浏览器,不需要安装驱动
# driver = webdriver.Edge ()
time.sleep(5)
# 3.打开Web页面
driver.get("http://121.43.169.97:8081/")

# 点击"有奖注册"
driver.find_element(by=By.CSS_SELECTOR, value=".reg").click()
# 进入注册页面,填写信息
driver.find_element(by=By.ID, value="phone").send_keys(fk.phone_number())
driver.find_element(by=By.ID, value="password").send_keys("123456abc")
driver.find_element(by=By.NAME, value="verifycode").send_keys("8888")
driver.find_element(by=By.CSS_SELECTOR, value=".get-phone-code.get-md").click()
time.sleep(3)
driver.find_element(by=By.CSS_SELECTOR, value="#phone_code").send_keys("666666")
time.sleep(3)
driver.find_element(by=By.CSS_SELECTOR, value=".lg-btn").click()
time.sleep(3)
# 进行开通资金托管
driver.find_element(by=By.CSS_SELECTOR, value=".blue").click()
time.sleep(3)
driver.find_element(by=By.CSS_SELECTOR, value="[name='realname']").send_keys(fk.name())
driver.find_element(by=By.CSS_SELECTOR, value="[name='card_id']").send_keys(fk.ssn())
driver.find_element(by=By.CSS_SELECTOR, value=".btn").click()
time.sleep(3)
driver.find_element(by=By.CSS_SELECTOR, value=".btn.ng-scope").click()
time.sleep(3)
# result = driver.find_element(by=By.XPATH, value="/html/body").text
# print(result)
# assert "UserRegister OK" == result

# 4.暂停
time.sleep(5)
# 5.关闭浏览器驱动对象
driver.quit()